using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Resources;
using System.Windows.Forms;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinTabControl;
using PluginFrame;

namespace PcrDataAnalysis
{
    public class FormCrossTalkOption : Form
    {
        protected ResourceManager mResourceManager;

        protected List<IPcrExperimentProject> mPcrExerimentProjects;

        protected UltraTabControl mOptionsTabControl;

        protected IConfigurationService mConfigurationSerivce;

        protected IPcrSystemService mPcrSystemService;

        protected IAnalysisService mAnalysisService;

        protected IPcrExperimentProjectService mPcrExperimentProjectService;

        private IContainer components;

        protected Panel panel1;

        protected Button btnConfirm;

        protected Button btnCancel;

        public FormCrossTalkOption(IApplication app, List<IPcrExperimentProject> pcrExerimentProjects)
        {
            InitializeComponent();
            mConfigurationSerivce = (IConfigurationService)app.GetService("ConfigurationService");
            mAnalysisService = (IAnalysisService)app.GetService("AnalysisService");
            mPcrSystemService = (IPcrSystemService)app.GetService("PcrSystemService");
            mPcrExperimentProjectService = (IPcrExperimentProjectService)app.GetService("PcrExperimentProjectService");
            mPcrExerimentProjects = pcrExerimentProjects;
            mResourceManager = ResourceManager.CreateFileBasedResourceManager("PcrDataAnalysis", app.GetResourceFolder() + GetType().Namespace + "\\", null);
            InitializeTab();
            base.DialogResult = DialogResult.Cancel;
        }

        protected void InitializeTab()
        {
            mOptionsTabControl = mAnalysisService.GenerateCrossTalkOptionTabControl(mPcrExerimentProjects);
            base.Controls.Add(mOptionsTabControl);
            mOptionsTabControl.BringToFront();
            panel1.SendToBack();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            foreach (UltraTab tab in mOptionsTabControl.Tabs)
            {
                if (!tab.Visible || !tab.Enabled)
                {
                    continue;
                }
                UltraTabPageControl tabPage = tab.TabPage;
                UltraGrid ultraGrid = tabPage.Controls[0] as UltraGrid;
                IPcrExperimentProject pcrExperimentProject = ultraGrid.Tag as IPcrExperimentProject;
                if (pcrExperimentProject == null)
                {
                    continue;
                }
                foreach (UltraGridRow row in ultraGrid.Rows)
                {
                    foreach (UltraGridCell cell in row.Cells)
                    {
                        pcrExperimentProject.CrossTalkValue[row.Index, cell.Column.Index] = (double)cell.Value;
                    }
                }
            }
            base.DialogResult = DialogResult.OK;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.Cancel;
            Close();
        }

        private void FormCrossTalkOption_Load(object sender, EventArgs e)
        {
            foreach (UltraTab tab in mOptionsTabControl.Tabs)
            {
                if (!tab.Visible || !tab.Enabled)
                {
                    continue;
                }
                UltraTabPageControl tabPage = tab.TabPage;
                UltraGrid ultraGrid = tabPage.Controls[0] as UltraGrid;
                IPcrExperimentProject pcrExperimentProject = ultraGrid.Tag as IPcrExperimentProject;
                IPcrExperiment activeFormCurrentExperiment = mPcrSystemService.GetActiveFormCurrentExperiment(null);
                bool flag = false;
                if (activeFormCurrentExperiment.HasPassword && !activeFormCurrentExperiment.PcrStructure.PcrDataFile.IsNewPcrFile && !activeFormCurrentExperiment.IsPasswordMatch)
                {
                    flag = true;
                }
                bool flag2 = false;
                if (!flag)
                {
                    if (pcrExperimentProject.ZonePasswordStatus == null)
                    {
                        pcrExperimentProject.ZonePasswordStatus = new bool[Enum.GetNames(typeof(ProjectPasswordEnum)).Length];
                    }
                    if (pcrExperimentProject.ZonePasswordStatus[3])
                    {
                        flag2 = !pcrExperimentProject.IsPasswordMatch;
                    }
                }
                if (!mPcrExperimentProjectService.GenerateCrossTalkGrid(pcrExperimentProject, ultraGrid, true, flag || flag2))
                {
                    tabPage.Enabled = false;
                    tab.Enabled = false;
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && components != null)
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PcrDataAnalysis.FormCrossTalkOption));
            this.panel1 = new System.Windows.Forms.Panel();
            this.btnConfirm = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.panel1.SuspendLayout();
            base.SuspendLayout();
            this.panel1.AccessibleDescription = null;
            this.panel1.AccessibleName = null;
            resources.ApplyResources(this.panel1, "panel1");
            this.panel1.BackgroundImage = null;
            this.panel1.Controls.Add(this.btnConfirm);
            this.panel1.Controls.Add(this.btnCancel);
            this.panel1.Font = null;
            this.panel1.Name = "panel1";
            this.btnConfirm.AccessibleDescription = null;
            this.btnConfirm.AccessibleName = null;
            resources.ApplyResources(this.btnConfirm, "btnConfirm");
            this.btnConfirm.BackgroundImage = null;
            this.btnConfirm.Font = null;
            this.btnConfirm.Name = "btnConfirm";
            this.btnConfirm.UseVisualStyleBackColor = true;
            this.btnConfirm.Click += new System.EventHandler(btnConfirm_Click);
            this.btnCancel.AccessibleDescription = null;
            this.btnCancel.AccessibleName = null;
            resources.ApplyResources(this.btnCancel, "btnCancel");
            this.btnCancel.BackgroundImage = null;
            this.btnCancel.Font = null;
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(btnCancel_Click);
            base.AccessibleDescription = null;
            base.AccessibleName = null;
            resources.ApplyResources(this, "$this");
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackgroundImage = null;
            base.Controls.Add(this.panel1);
            this.Font = null;
            base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            base.Icon = null;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FormCrossTalkOption";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.Load += new System.EventHandler(FormCrossTalkOption_Load);
            this.panel1.ResumeLayout(false);
            base.ResumeLayout(false);
        }
    }
}
